package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.RechargeInfoService;
import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.vo.account.RechargeInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "充值管理")
@RestController
@RequestMapping("api/account/rechargeInfo")
@SuppressWarnings({"all"})
public class RechargeInfoApiController {

    @Autowired
    private RechargeInfoService rechargeInfoService;


	/**
	 * 提交充值
	 * @param rechargeInfoVo
	 * @return
	 */
    @TsLogin
    @Operation(summary = "充值")
    @PostMapping("/submitRecharge")
    public Result submitRecharge(@RequestBody RechargeInfoVo rechargeInfoVo) {
        //获取用户id
        Long userId = AuthContextHolder.getUserId();
        //调用服务层方法;将数据保存到rechargeInfo表中
        String orderNo = rechargeInfoService.submitRecharge(rechargeInfoVo, userId);
		//创建map集合
		Map<String, Object> map = new HashMap<>();
		map.put("orderNo", orderNo);
        //返回结果
        return Result.ok(map);
    }
}

